//生成逃离点
//生成逃离点（被服务器调用）

private["_marker", "_pos_mk"];

//立即清理
//[] call fn_cleanup_all;

if(Param_EndSuport == 2) then
{
	//支援
	//武直兜风x1
	//[as_end_pos] spawn fn_mi48;
	//sleep 5;

	//主战1 apc2 防空3
	private _type_0 = "O_T_MBT_02_cannon_ghex_F";
	if(Param_Version >= 183) then
	{
		_type_0 = "O_MBT_04_cannon_F";
	};

	[as_end_pos, _type_0, "O_Heli_Transport_04_covered_F", 0] spawn fn_supplyDrop;
	sleep 5;

	[as_end_pos, "O_T_APC_Tracked_02_cannon_ghex_F", "O_Heli_Transport_04_covered_F", 0] spawn fn_supplyDrop;
	sleep 5;
	//[as_end_pos, "O_T_APC_Tracked_02_cannon_ghex_F", "O_Heli_Transport_04_covered_F", 0] spawn fn_supplyDrop;
	//sleep 5;

	[as_end_pos, "O_APC_Tracked_02_AA_F", "O_Heli_Transport_04_covered_F",0] spawn fn_supplyDrop;
	sleep 5;
	//[as_end_pos, "O_APC_Tracked_02_AA_F", "O_Heli_Transport_04_covered_F", 0] spawn fn_supplyDrop;
	//sleep 5;
	//[as_end_pos, "O_APC_Tracked_02_AA_F", "O_Heli_Transport_04_covered_F", 0] spawn fn_supplyDrop;
	//sleep 5;
}
else
{
	if(Param_EndSuport == 1) then
	{
		[as_end_pos, "Box_East_WpsLaunch_F", "O_Heli_Transport_04_covered_F",0] spawn fn_supplyDrop;
		sleep 5;
		
		[as_end_pos, "Box_East_WpsSpecial_F", "O_Heli_Transport_04_covered_F",0] spawn fn_supplyDrop;
		sleep 5;
		
		[as_end_pos, "Box_East_Support_F", "O_Heli_Transport_04_covered_F",0] spawn fn_supplyDrop;
		sleep 5;
	};
};
///////////////////////////////////////////////////////////////////////////////

uisleep 10;

private _player = call fn_getLivePlayer;
[getPos _player, 3.0] spawn fn_aiNeedSupport;

//呆了太久
/*
[] spawn
{
	uisleep 600;
	{
		if((_x distance as_end_pos) < 200) exitWith
		{
			//2倍美军
			private _group2 = [getPos _x, call fn_aiNum, 5, 750, 3]call fn_createGroup;
			[_group2, _player] call fn_addWaypoint;
			[_group2] spawn fn_controlGroup;
			
			_group2 = [getPos _x, call fn_aiNum, 5, 750, 3]call fn_createGroup;
			[_group2, _player] call fn_addWaypoint;
			[_group2] spawn fn_controlGroup;
			
			sleep 5;
			//CTRG x 3
			[asg_6, getPos _x] spawn fn_createG;
			sleep 5;
			[asg_6, getPos _x] spawn fn_createG;
			sleep 5;
			[asg_6, getPos _x] spawn fn_createG;
			sleep 5;
			//武直 x2
			[asg_10, getPos _x] spawn fn_createG;
			sleep 5;
			[asg_10, getPos _x] spawn fn_createG;
			sleep 5;
			//装甲 *2
			[asg_18, getPos _x] spawn fn_createG;
			sleep 5;
			[asg_18, getPos _x] spawn fn_createG;
			sleep 5;
			//坦克
			sleep 5;
			[asg_17, getPos _x] spawn fn_createG;
		};
	}forEach (call fn_getPlayerRed);
};
*/

///////////////////////////////////////////////////////////////////////////////
//寻找空地（3km-5km）
private _time = time + 60;//防止超时
private _timeOut = false;

_pos_mk = as_end_pos getPos[(3000 + random 5000) * as_near_scale, random 360];
while{!([_pos_mk, 5] call fn_checkPos) 
|| {[_pos_mk, 800 * as_near_scale, "mk_"] call fn_checkNearMarker}
|| {_pos_mk call fn_isOutMap}}do
{
	if(time > _time) exitWith{_timeOut = true;};
	_pos_mk = as_end_pos getPos[(3000 + random 5000) * as_near_scale, random 360];
};


//_timeOut = true;

if(_timeOut)then{
	_pos_mk = as_start_pos getPos[0, 0];
};

//创建标记
_marker = createMarkerLocal  ["mk_escape", _pos_mk];

//设置标记
_marker setMarkerShapeLocal "ICON";
_marker setMarkerTypeLocal "hd_pickup";		
_marker setMarkerColorLocal "ColorGreen";
_marker setMarkerDirLocal 0;
_marker setMarkerText "撤退点";

//绿军隐藏标记
["mk_escape", 0] remoteExec ['setMarkerAlphaLocal', resistance];



//_____________________________清障碍物_____________________________
[_pos_mk, 25] call fn_cleanupTerrain;


/*
private _veh = createVehicle ["O_T_VTOL_02_infantry_dynamicLoadout_F", _pos_mk, [], 0, "NONE"];
_veh setVariable["no_cleanup", true];
*/



//改为了 撤离点防守 保护联络员
[_pos_mk] spawn fn_createDefend;


[east, "STR_TAG_O_10_0", "STR_TAG_O_11_1"] remoteExec ["fn_talk", east];


//as_escape_pos = _pos_mk;

private _pos_df = _pos_mk getPos [16, 90]; 
_pos_df = _pos_df getPos [6.5, 0]; 


//撤离点 x + 9m
[_pos_df, 2, 4, "", 15, 400, 1200, 400, 90, 6, 1200, 5,
	[	
		['Land_BagFence_Long_F',[-1,-27,1.90735e-006],0,false],
		['Land_BagFence_Long_F',[2,-27,1.90735e-006],0,false],
		['Land_BagFence_Long_F',[-4,-27,1.90735e-006],0,false],
		['Land_BagFence_Long_F',[8,-27,1.90735e-006],0,false],
		['Land_BagFence_Long_F',[-7,-27,1.90735e-006],0,false],
		['Land_BagFence_Long_F',[5,-27,1.90735e-006],0,false],
		['Land_BagFence_Round_F',[-12,-26,1.90735e-006],45,false],
		['Land_Mil_WallBig_4m_F',[8,8,1.90735e-006],180,false],
		['Land_Mil_WallBig_4m_damaged_center_F',[-8,8,1.90735e-006],180,false],
		['Land_Mil_WallBig_4m_damaged_center_F',[-12,8,1.90735e-006],180,false],
		['Land_Mil_WallBig_4m_damaged_center_F',[0,8,1.90735e-006],180,false],
		['Land_Mil_WallBig_4m_damaged_center_F',[-4,8,1.90735e-006],180,false],
		['Land_Mil_WallBig_4m_damaged_center_F',[-20,8,1.90735e-006],180,false],
		['Land_Mil_WallBig_4m_damaged_center_F',[-16,8,1.90735e-006],180,false],
		['Land_Mil_WallBig_4m_damaged_right_F',[4,8,1.90735e-006],180,false],
		//['O_Heli_Light_02_dynamicLoadout_F',[-12.998,23.7764,0.00557947],359.959,false],
		['Land_Mil_WallBig_4m_F',[26,-25,1.90735e-006],270,false],
		['Land_Mil_WallBig_4m_F',[26,-29,1.90735e-006],270,false],
		['Land_Mil_WallBig_4m_F',[26,-21,1.90735e-006],270,false],
		['Land_Mil_WallBig_4m_F',[26,-17,1.90735e-006],270,false],
		['Land_Cargo_Patrol_V1_F',[19,-25,2.38419e-006],0,false],	
		['Land_Mil_WallBig_4m_damaged_center_F',[20,-31,1.90735e-006],0,false],
		['Land_Mil_WallBig_4m_damaged_center_F',[24,-31,1.90735e-006],0,false],
		['Land_Mil_WallBig_4m_damaged_center_F',[16,-31,1.90735e-006],0,false],
		['Land_Mil_WallBig_4m_F',[26,-9,1.90735e-006],270,false],
		['Land_Mil_WallBig_4m_F',[26,-13,1.90735e-006],270,false],
		['Land_Mil_WallBig_4m_F',[20,8,1.90735e-006],180,false],
		['Land_Mil_WallBig_4m_F',[24,8,1.90735e-006],180,false],
		['Land_Mil_WallBig_4m_F',[16,8,1.90735e-006],180,false],
		['Land_Mil_WallBig_4m_F',[12,8,1.90735e-006],180,false],
		//['O_T_MBT_02_arty_ghex_F',[15.9961,-11.9994,-0.00575018],270,false],
		['Land_Mil_WallBig_4m_damaged_left_F',[26,6,1.90735e-006],270,false],
		['Land_Mil_WallBig_4m_damaged_center_F',[26,3,1.90735e-006],270,false],
		['Land_Mil_WallBig_4m_damaged_center_F',[26,-1,1.90735e-006],270,false],
		['Land_Cargo_Patrol_V3_derelict_F',[20,1,1.90735e-006],90,false],
		['Land_Mil_WallBig_4m_damaged_right_F',[26,-5,1.90735e-006],270,false],
		//['O_Heli_Attack_02_dynamicLoadout_F',[11.9976,22.9689,0.00187302],0.00497021,false],
		['O_HMG_01_high_F',[6.52539,-24.3766,-0.0121169],180,false],
		['O_GMG_01_high_F',[-10.5356,-24.2968,-0.011806],225,false],
		['O_Mortar_01_F',[2,-24.0004,0.0369039],180,true],
		//['O_Mortar_01_F',[-3,-24.0004,0.0369039],180.001,true],
		['Land_HelipadSquare_F',[-16.0,-8,0],0,false],
		['Flag_CSAT_F',[20.9385,-25.8516,6.6649],0,true]
	],
	[
	"O_T_Recon_TL_F",
	"O_T_Recon_Medic_F",
	"O_T_Recon_LAT_F",
	"O_T_ghillie_tna_F",
	"O_T_Spotter_F"]
] call fn_createE;



/*
[_veh] spawn
{
	private _veh = _this select 0;
	waitUntil{sleep 1;!alive _veh};

	["End6",false]remoteExec['BIS_fnc_endMission',east,false];
	["End12",true]remoteExec['BIS_fnc_endMission',resistance,false];
	"End13" call BIS_fnc_endMissionServer;
};
*/



uisleep 10;
//传送玩家
if(Param_EndTP == 1) then
{	
	private _box = "C_IDAP_supplyCrate_F" createVehicle (as_end_pos getPos [2 + random 8, random 360]);
	_box allowDamage false;
	clearItemCargoGlobal _box;
	{
		waitUntil{moveOut _x; vehicle _x == _x};
		_x setPos (as_end_pos getPos [1, random 360]);
		
		
		[_box, 4] call fn_createSupply;	
	}forEach (call fn_getPlayerRed);
};		
			

